//
// Created by steven on 2017/2/24.
// Copyright (c) 2017 steven. All rights reserved.
//

#import "GMComboTableViewCell.h"
#import "GMButton.h"


@implementation GMComboTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupMainView];
    }

    return self;
}

- (void)setupMainView {
    self.backgroundColor = BACKGROUND_COLOR;
    [self addSubview:self.contentImgaeView];
    [self.contentImgaeView addSubview:self.iconImageView];
    [self.contentImgaeView addSubview:self.countTitleLabel];
    [self.contentImgaeView addSubview:self.countLabel];
    [self.contentImgaeView addSubview:self.scoreImageView];
    [self.contentImgaeView addSubview:self.titleLabel];
    [self.contentImgaeView addSubview:self.scoreLabel];
    [self.contentImgaeView addSubview:self.priceLabel];
    
    // content image view
    [self.contentImgaeView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:10];
    [self.contentImgaeView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:10];
    [self.contentImgaeView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:20];
    [self.contentImgaeView autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:20];
    
    // icon image view
    [self.iconImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.iconImageView autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:27];
    [self.iconImageView autoSetDimensionsToSize:CGSizeMake(40, 68)];
    
    // score image view
    [self.scoreImageView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.scoreImageView autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.iconImageView withOffset:18];
    
    // score label
    [self.scoreLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.scoreImageView];
    [self.scoreLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.scoreImageView withOffset:2];
    
    // count title label
    [self.countTitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:self.scoreImageView];
    [self.countTitleLabel autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.scoreImageView withOffset:-2];
    
    // cout label
    [self.countLabel autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.countTitleLabel];
    [self.countLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.countTitleLabel withOffset:10];
    
    // title label
    [self.titleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:self.scoreImageView];
    [self.titleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.scoreImageView withOffset:2];
    
    // price label
    [self.priceLabel autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
    [self.priceLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:38];
}

- (UIImageView *)contentImgaeView {
    if (!_contentImgaeView) {
        _contentImgaeView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"combo-background"]];
    }
    return _contentImgaeView;
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guard-icon"]];
    }
    
    return _iconImageView;
}

- (UILabel *)countTitleLabel {
    if (!_countTitleLabel) {
        _countTitleLabel = [[UILabel alloc] init];
        _countTitleLabel.font = [UIFont systemFontOfSize:14];
        _countTitleLabel.text = @"守卫侠个数";
    }
    
    return _countTitleLabel;
}

- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [[UILabel alloc] init];
        _countLabel.textColor = BUTTON_ACTIVE_COLOR;
        _countLabel.font = [UIFont systemFontOfSize:24];
    }
    
    return _countLabel;
}

- (UIImageView *)scoreImageView {
    if (!_scoreImageView) {
        _scoreImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"score"]];
    }
    
    return _scoreImageView;
}

- (UILabel *)scoreLabel {
    if (!_scoreLabel) {
        _scoreLabel = [[UILabel alloc] init];
        _scoreLabel.font = [UIFont systemFontOfSize:10];
        _scoreLabel.textColor = [UIColor grayColor];
    }
    
    return _scoreLabel;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:10];
        _titleLabel.textColor = [UIColor grayColor];
    }
    
    return _titleLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = [UIColor whiteColor];
        _priceLabel.font = [UIFont systemFontOfSize:24];
    }
    
    return _priceLabel;
}

@end
